package com.transfiguro.utilities;

import com.transfiguro.datamodel.javamodels.JavaDoc;
import com.transfiguro.datamodel.javamodels.Variable;
import japa.parser.ast.body.JavadocComment;
import japa.parser.ast.body.Parameter;

import java.util.ArrayList;
import java.util.List;

/**
 * This class provides several utility functions for use across various parser classes
 */
public class Utilities {

    /**
     * Empty constructor. Provided for future use
     */
    public Utilities() {
    }

    /**
     * This method takes a list of {@link Parameter}s and returns a list of
     * {@link Variable}s
     *
     * @param parameters The list of <code>parameters</code>
     * @return List of <code>variables</code>
     */
    public static List<Variable> getInputParameters(final List<Parameter> parameters) {
        List<Variable> variables = new ArrayList<Variable>();
        if (parameters != null) {
            for (final Parameter parameter : parameters) {
                Variable variable = new Variable();
                variable.setAccessModifier(parameter.getModifiers());
                variable.setVariableName(parameter.getId().getName());
                variable.setType(parameter.getType().toString());
                variables.add(variable);
            }
        }
        return variables;
    }

    /**
     * This method takes a {@link JavadocComment} and returns a {@link JavaDoc}
     *
     * @param comment The <code>JavadocComment</code> to be converted to <code>JavaDoc</code>
     * @return A <code>JavaDoc</code> comment
     */
    public static JavaDoc getComment(final JavadocComment comment) {
        JavaDoc javaDoc = new JavaDoc();
        if (comment != null) {
            javaDoc.setContent(comment.toString());
        }
        return javaDoc;
    }
}
